package org.springblade.tms.module.exceptioncost.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.jackson.JsonUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.tms.global.enums.WhetherEnum;
import org.springblade.tms.module.common.dto.DeleteDto;
import org.springblade.tms.module.exceptioncost.base.ExtraordinaryFeeService;
import org.springblade.tms.module.exceptioncost.entity.TMExceptionCost;
import org.springblade.tms.module.exceptioncost.service.IExceptionCostService;
import org.springblade.tms.module.exceptioncost.vo.TMExceptionCostVO;
import org.springblade.tms.module.exceptioncost.wrapper.ExceptionCostWrapper;
import org.springblade.tms.module.exceptionrecord.entity.TMExceptionRecord;
import org.springblade.tms.module.exceptionrecord.service.IExceptionRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;

/**
 * @projectName: BladeX
 * @package: org.springblade.tms.module.exceptioncost.controller
 * @className: ExtraordinaryFeeController
 * @author: yr
 * @description: 异常费用接口
 * @date: 2022/4/19 14:31
 */
@RestController
@AllArgsConstructor
@RequestMapping("exceptionCost/ExtraordinaryFee")
@Api(value = "异常费用-yr", tags = "异常费用接口-yr")
public class ExtraordinaryFeeController {
	@Resource
	private IExceptionCostService exceptionCostService;
	@Resource
	private IExceptionRecordService exceptionRecordService;
	@Resource
	private ExtraordinaryFeeService extraordinaryFeeService;
	/**
	 * 分页 异常费用
	 */
	@GetMapping("/list")
	@ApiOperationSupport(order = 1)
	@ApiOperation(value = "异常费用列表", notes = "传入异常记录id")
	public R<IPage<TMExceptionCostVO>> list(Long id, Query query) {
		return extraordinaryFeeService.list(id,query);
	}

	/**
	 * 新增或修改 异常费用
	 */
	@PostMapping("/saveOrUpdate")
	@ApiOperationSupport(order = 2)
	@ApiOperation(value = "新增或修改", notes = "传入exceptionCost")
	public R saveOrUpdate(@Valid @RequestBody TMExceptionCost TMExceptionCost) {
		return R.status(exceptionCostService.saveOrUpdate(TMExceptionCost));
	}

	/**
	 * 提交
	 */
	@PostMapping("/submit")
	@ApiOperationSupport(order = 3)
	@ApiOperation(value = "提交", notes = "传入异常记录id")
	public R submit(@RequestBody String id) {
		Map<String, String> idMap = JsonUtil.parse(id, Map.class);
		return extraordinaryFeeService.submit(idMap.get("id"));
	}

	/**
	 * 删除 异常费用
	 */
	@PostMapping("/remove")
	@ApiOperationSupport(order = 4)
	@ApiOperation(value = "删除异常费用", notes = "传入ids")
	public R remove(@RequestParam String ids) {
		return R.status(exceptionCostService.deleteLogic(Func.toLongList(ids)));
	}
}
